// 用户相关接口
import request from '../utils/request.js'
// 登录
export const login = function (data) {
  return request({
    method: 'post',
    url: '/v1_0/authorizations',
    data
  })
}
// 发送验证码
export const sendSms = function (mobile) {
  return request({
    method: 'get',
    url: '/v1_0/sms/codes/' + mobile
  })
}
// 获取用户个人资料
export const getUserInfo = function () {
  return request({
    method: 'get',
    url: '/v1_0/user'
  })
}
// 获取用户频道列表
export const getUserChannels = function () {
  return request({
    method: 'get',
    url: '/v1_0/user/channels'
  })
}
// 关注用户
export const addFollow = function (target) {
  return request({
    method: 'post',
    url: '/v1_0/user/followings',
    data: {
      target
    }
  })
}
// 取消关注用户
export const deleteFollow = function (target) {
  return request({
    method: 'delete',
    url: `/v1_0/user/followings/${target}`
  })
}
// 收藏用户
export const addCollect = function (target) {
  return request({
    method: 'post',
    url: '/v1_0/article/collections',
    data: {
      target
    }
  })
}
// 取消收藏用户
export const deleteCollect = function (target) {
  return request({
    method: 'delete',
    url: `/v1_0/article/collections/${target}`
  })
}
/**
 * 点赞
 */
export const addLike = articleId => {
  return request({
    method: 'POST',
    url: '/v1_0/article/likings',
    data: {
      target: articleId
    }
  })
}

/**
 * 取消点赞
 */
export const deleteLike = articleId => {
  return request({
    method: 'DELETE',
    url: `/v1_0/article/likings/${articleId}`
  })
}
/**
 * 获取用户个人资料
 */
// 获取指定用户信息
export const getUserProfile = () => {
  return request({
    method: 'GET',
    url: '/v1_0/user/profile'
  })
}
/**
 * 更新昵称
 */
export const updateUserName = data => {
  return request({
    method: 'PATCH',
    url: '/v1_0/user/profile',
    data
  })
}
/**
 * 更新头像
 */
export const updateUserAvatar = data => {
  return request({
    method: 'PATCH',
    url: '/v1_0/user/photo',
    data
  })
}
